+Enable Atom support for that script that isn't migrated to Querypage.php class yet.
[lhc/web/wiklou.git] / includes / SpecialRecentchanges.php
1 <?php
2
3 include_once( "Feed.php" );
4
5 function wfSpecialRecentchanges( $par )
6 {
7 global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname;
8 global $wgRequest, $wgSitename, $wgLanguageCode;
9 $fname = "wfSpecialRecentchanges";
10
11 # Get query parameters
12 $feedFormat = $wgRequest->getVal( "feed" );
13
14 // imported from Feed.php
15 $wgFeedClasses = array (
16 "rss" => "RSSFeed",
17 "atom" => "AtomFeed",
18 );
19 // end of import
20
21 $defaultDays = $wgUser->getOption( 'rcdays' );
22 if ( !$defaultDays ) {
23 $defaultDays = 3;
24 }
25
26 $days = $wgRequest->getInt( 'days', $defaultDays );
27 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor' ) ) ? 1 : 0;
28 $from = $wgRequest->getText( 'from' );
29 $hidebots = $wgRequest->getBool( 'hidebots', true ) ? 1 : 0;
30 $hideliu = $wgRequest->getBool( 'hideliu', false ) ? 1 : 0;
31
32 # Get query parameters from path
33 if( $par ) {
34 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
35 if( in_array( "hidebots", $bits ) ) $hidebots = 1;
36 if( in_array( "bots", $bits ) ) $hidebots = 0;
37 if( in_array( "hideminor", $bits ) ) $hideminor = 1;
38 if( in_array( "minor", $bits ) ) $hideminor = 0;
39 if( in_array( "hideliu", $bits) ) $hideliu = 1;
40 }
41
42 $sql = "SELECT MAX(rc_timestamp) AS lastmod FROM recentchanges";
43 $res = wfQuery( $sql, DB_READ, $fname );
44 $s = wfFetchObject( $res );
45 # 10 seconds server-side caching max
46 $wgOut->setSquidMaxage( 10 );
47 if( $wgOut->checkLastModified( $s->lastmod ) ){
48 # Client cache fresh and headers sent, nothing more to do.
49 return;
50 }
51
52 $rctext = wfMsg( "recentchangestext" );
53
54 # The next few lines can probably be commented out now that wfMsg can get text from the DB
55 $sql = "SELECT cur_text FROM cur WHERE cur_namespace=4 AND cur_title='Recentchanges'";
56 $res = wfQuery( $sql, DB_READ, $fname );
57 if( ( $s = wfFetchObject( $res ) ) and ( $s->cur_text != "" ) ) {
58 $rctext = $s->cur_text;
59 }
60
61 $wgOut->addWikiText( $rctext );
62
63 list( $limit, $offset ) = wfCheckLimits( 100, "rclimit" );
64 $now = wfTimestampNow();
65 $cutoff_unixtime = time() - ( $days * 86400 );
66 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
67 $cutoff = wfUnix2Timestamp( $cutoff_unixtime );
68 if(preg_match('/^[0-9]{14}$/', $from) and $from > $cutoff) {
69 $cutoff = $from;
70 } else {
71 unset($from);
72 }
73
74 $sk = $wgUser->getSkin();
75 $showhide = array( wfMsg( "show" ), wfMsg( "hide" ));
76
77 if ( $hideminor ) {
78 $hidem = "AND rc_minor=0";
79 } else {
80 $hidem = "";
81 }
82
83 if( $hidebots ) {
84 $hidem .= " AND rc_bot=0";
85 }
86
87 if ( $hideliu ) {
88 $hidem .= " AND rc_user=0";
89 }
90 $hideliu = ($hideliu ? 1 : 0);
91 #$hideparams = "hideminor={$hideminor}&hideliu={$hideliu}&hidebots={$hidebots}";
92 $urlparams = array( "hideminor" => $hideminor, "hideliu" => $hideliu, "hidebots" => $hidebots );
93 $hideparams = wfArrayToCGI( $urlparams );
94
95 $minorLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
96 $showhide[1-$hideminor], wfArrayToCGI( array( "hideminor" => 1-$hideminor ), $urlparams ) );
97 $botLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
98 $showhide[1-$hidebots], wfArrayToCGI( array( "hidebots" => 1-$hidebots ), $urlparams ) );
99 $liuLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
100 $showhide[1-$hideliu], wfArrayToCGI( array( "hideliu" => 1-$hideliu ), $urlparams ) );
101
102 $uid = $wgUser->getID();
103 $sql2 = "SELECT recentchanges.*" . ($uid ? ",wl_user" : "") . " FROM recentchanges " .
104 ($uid ? "LEFT OUTER JOIN watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
105 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
106 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
107
108 $res = wfQuery( $sql2, DB_READ, $fname );
109 $rows = array();
110 while( $row = wfFetchObject( $res ) ){
111 $rows[] = $row;
112 }
113
114 if(isset($from)) {
115 $note = wfMsg( "rcnotefrom", $wgLang->formatNum( $limit ),
116 $wgLang->timeanddate( $from, true ) );
117 } else {
118 $note = wfMsg( "rcnote", $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
119 }
120 $wgOut->addHTML( "\n<hr/>\n{$note}\n<br/>" );
121
122 $note = rcDayLimitLinks( $days, $limit, "Recentchanges", $hideparams, false, $minorLink, $botLink, $liuLink );
123
124 $note .= "<br/>\n" . wfMsg( "rclistfrom",
125 $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
126 $wgLang->timeanddate( $now, true ), "{$hideparams}&from=$now" ) );
127
128 $wgOut->addHTML( "{$note}\n" );
129
130 if( isset($wgFeedClasses[$feedFormat]) ) {
131 $feed = new $wgFeedClasses[$feedFormat](
132 $wgSitename . " - " . wfMsg( "recentchanges" ) . " [" . $wgLanguageCode . "]",
133 htmlspecialchars( wfMsg( "recentchangestext" ) ),
134 $wgTitle->getFullUrl() );
135 $feed->outHeader();
136 foreach( $rows as $obj ) {
137 $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
138 $item = new FeedItem(
139 $title->getPrefixedText(),
140 htmlspecialchars( $obj->rc_comment ),
141 $title->getFullURL(),
142 $obj->rc_timestamp,
143 $obj->rc_user_text,
144 htmlspecialchars( $obj->rc_comment )
145 );
146 $feed->outItem( $item );
147 }
148 $feed->outFooter();
149 } else {
150 $wgOut->setSyndicated( true );
151 $s = $sk->beginRecentChangesList();
152 $counter = 1;
153 foreach( $rows as $obj ){
154 if( $limit == 0) {
155 break;
156 }
157
158 if ( ! ( $hideminor && $obj->rc_minor ) ) {
159 $rc = RecentChange::newFromRow( $obj );
160 $rc->counter = $counter++;
161 $s .= $sk->recentChangesLine( $rc, !empty( $obj->wl_user ) );
162 --$limit;
163 }
164 }
165 $s .= $sk->endRecentChangesList();
166 $wgOut->addHTML( $s );
167 }
168 wfFreeResult( $res );
169 }
170
171 function rcCountLink( $lim, $d, $page="Recentchanges", $more="" )
172 {
173 global $wgUser, $wgLang;
174 $sk = $wgUser->getSkin();
175 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
176 ($lim ? $wgLang->formatNum( "{$lim}" ) : wfMsg( "all" ) ), "{$more}" .
177 ($d ? "days={$d}&" : "") . "limit={$lim}" );
178 return $s;
179 }
180
181 function rcDaysLink( $lim, $d, $page="Recentchanges", $more="" )
182 {
183 global $wgUser, $wgLang;
184 $sk = $wgUser->getSkin();
185 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
186 ($d ? $wgLang->formatNum( "{$d}" ) : wfMsg( "all" ) ), "{$more}days={$d}" .
187 ($lim ? "&limit={$lim}" : "") );
188 return $s;
189 }
190
191 function rcDayLimitLinks( $days, $limit, $page="Recentchanges", $more="", $doall = false, $minorLink = "",
192 $botLink = "", $liuLink = "" )
193 {
194 if ($more != "") $more .= "&";
195 $cl = rcCountLink( 50, $days, $page, $more ) . " | " .
196 rcCountLink( 100, $days, $page, $more ) . " | " .
197 rcCountLink( 250, $days, $page, $more ) . " | " .
198 rcCountLink( 500, $days, $page, $more ) .
199 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
200 $dl = rcDaysLink( $limit, 1, $page, $more ) . " | " .
201 rcDaysLink( $limit, 3, $page, $more ) . " | " .
202 rcDaysLink( $limit, 7, $page, $more ) . " | " .
203 rcDaysLink( $limit, 14, $page, $more ) . " | " .
204 rcDaysLink( $limit, 30, $page, $more ) .
205 ( $doall ? ( " | " . rcDaysLink( $limit, 0, $page, $more ) ) : "" );
206 $shm = wfMsg( "showhideminor", $minorLink, $botLink, $liuLink );
207 $note = wfMsg( "rclinks", $cl, $dl, $shm );
208 return $note;
209 }
210
211 # Obsolete? Isn't called from anywhere and $mlink isn't defined
212 function rcLimitLinks( $page="Recentchanges", $more="", $doall = false )
213 {
214 if ($more != "") $more .= "&";
215 $cl = rcCountLink( 50, 0, $page, $more ) . " | " .
216 rcCountLink( 100, 0, $page, $more ) . " | " .
217 rcCountLink( 250, 0, $page, $more ) . " | " .
218 rcCountLink( 500, 0, $page, $more ) .
219 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
220 $note = wfMsg( "rclinks", $cl, "", $mlink );
221 return $note;
222 }
223
224 ?>